﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using DOAN.Public;

namespace DOAN.DLL
{
    public class HopDongDAL
    {
        ClsConnection cls;

        public HopDongDAL()
        {
            cls = new ClsConnection();
        }

        public DataTable Load()
        {
            return cls.GetData("HOPDONG_LOAD");
        }

        public int Insert(HopDongPublic p)
        {
            int Nparameter = 13;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];
            name[0] = "@MaHopDong";
            name[1] = "@MaTinhTrang";
            name[2] = "@MaGoiCuoc";
            name[3] = "@NgayBatDauSuDung";
            name[4] = "@DiaChiCaiDat";
            name[5] = "@DiaChiHoaDon";
            name[6] = "@SoLuongTaiKhoan";
            name[7] = "@PhiHoaMang";
            name[8] = "@NgayThanhToanDK";
            name[9] = "@NgayDangKy";
            name[10] = "@DiaChiIP";
            name[11] = "@MaKhachHang";
            name[12] = "@HopDong_Id";

            value[0] = p.MaHopDong;
            value[1] = p.MaTinhTrang;
            value[2] = p.MaGoiCuoc;
            value[3] = p.NgayBatDauSuDung;
            value[4] = p.DiaChiCaiDat;
            value[5] = p.DiaChiHoaDon;
            value[6] = p.SoLuongTaiKhoan;
            value[7] = p.PhiHoaMang;
            value[8] = p.NgayThanhToanDK;
            value[9] = p.NgayDK;
            value[10] = p.DiaChiIP;
            value[11] = p.MaKhachHang;
            value[12] = p.HopDong_Id;

            return cls.UpdateData("HOPDONG_INSERT", name, value, Nparameter);
        }

        public int Update(HopDongPublic p)
        {
            int Nparameter = 13;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];
            name[0] = "@MaHopDong";
            name[1] = "@MaTinhTrang";
            name[2] = "@MaGoiCuoc";
            name[3] = "@NgayBatDauSuDung";
            name[4] = "@DiaChiCaiDat";
            name[5] = "@DiaChiHoaDon";
            name[6] = "@SoLuongTaiKhoan";
            name[7] = "@PhiHoaMang";
            name[8] = "@NgayThanhToanDK";
            name[9] = "@NgayDangKy";
            name[10] = "@DiaChiIP";
            name[11] = "@MaKhachHang";
            name[12] = "@HopDong_Id";

            value[0] = p.MaHopDong;
            value[1] = p.MaTinhTrang;
            value[2] = p.MaGoiCuoc;
            value[3] = p.NgayBatDauSuDung;
            value[4] = p.DiaChiCaiDat;
            value[5] = p.DiaChiHoaDon;
            value[6] = p.SoLuongTaiKhoan;
            value[7] = p.PhiHoaMang;
            value[8] = p.NgayThanhToanDK;
            value[9] = p.NgayDK;
            value[10] = p.DiaChiIP;
            value[11] = p.MaKhachHang;
            value[12] = p.HopDong_Id;

            return cls.UpdateData("HOPDONG_UPDATE", name, value, Nparameter);
        }

        public int Delete(HopDongPublic p)
        {
            int Nparameter = 1;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];
            name[0] = "@MaHopDong";
            value[0] = p.MaHopDong;
            return cls.UpdateData("HOPDONG_DELETE", name, value, Nparameter);
        }

        public DataTable Load_MaKH(KhachHangPublic p)
        {
            int Nparameter = 1;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];
            name[0] = "@MaKhachHang";
            value[0] = p.MaKhachHang;
            return cls.GetData("HOPDONG_MAKH", name, value, Nparameter);
        }
    }
}
